package net.pinnoocle.playcommon.password;


/**
 * 密码工具类
 *
 * @author ye
 * @Description
 * @create 2021-09-02 16:19
 */
public class PasswordUtils {

  private static PasswordEncoder passwordEncoder = new Sha512PasswordEncoder();

  /**
   * 加密
   *
   * @param str 字符串
   * @return 返回加密字符串
   */
  public static String
  encode(String str) {
    return passwordEncoder.encode(str);
  }


  /**
   * 比较密码是否相等
   *
   * @param str 明文密码
   * @param password 加密后密码
   * @param timestamp 时间戳
   * @return true：成功    false：失败
   */
  public static boolean matches(String str, Long timestamp, String password) {
    return passwordEncoder.matches(str + timestamp, password);
  }

  public static void main(String[] args) {
    String str = "c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec";
    Long time = 1639186482857L;
    String password = encode(str+time);

    System.out.println(password);
    System.out.println(matches(str, time, password));
  }

}
